﻿@using Model;
@{
    SiteSecurity.RequireAuthenticatedUser();

    Layout = "~/Shared/_SiteLayout.cshtml";
    Page.Title = "View Result";

    List<Question> questions = SiteHelper.GetAllQuestions();

    int userId = SiteSecurity.GetUserId();

    Question champs = questions.FirstOrDefault(x => x.Results == questions.Max(p => p.Results));

    questions = questions.FindAll(x => x.UserId == userId);

    double percentageResult = (double)questions.Sum(x => x.Results);

    percentageResult = percentageResult / questions.Count;

    int totalAttendQuestion = questions.Count;
    int rightAnswer = questions.Count(x => x.IsAnswered == 2);
    int wrongAnswer = questions.Count(x => x.IsAnswered == 3);

    int notAnswered = totalAttendQuestion - (rightAnswer + wrongAnswer);
    List<Question> questionList = new List<Question>();

    foreach (Question item in questions)
    {
        if (string.IsNullOrEmpty(item.AnswerStatus))
        {
            //questions.Remove(item);
            item.AnswerStatus = SiteHelper.GetStatus(item.IsAnswered);
            questionList.Add(item);
        }
    }

    questions = questionList;

    var grid = new WebGrid(source: questions, rowsPerPage: WebSite.RowsPerPage);
}
<hgroup class="title">
    <h1>Your Result Card</h1>
</hgroup>
<fieldset>
    <legend>Result</legend>
    <div id="grid">
        @grid.GetHtml(
                tableStyle: "gridTable",
                headerStyle: "gridTableHeader",
                rowStyle: "rowstyle",
                alternatingRowStyle: "alternaterowstyle",
                columns: grid.Columns(
                grid.Column("Questions", "Questions"),
                grid.Column("TotalAnsweringTime", "Total Answering Time (Sec)", style: "text-align-center"),
                grid.Column("SpendingTime", "Spending Time (Sec)", style: "text-align-center"),
                grid.Column("IsAnswered", "Answer Condition", style: "text-align-center"),
                         grid.Column("AnswerStatus", "Answer Status", style: "text-align-center AnswerStatus"),
                grid.Column("Results", "Intelisense (%)", format: @<span>@item.Results.ToString("N")</span>, style: "text-align-center"),
                grid.Column("", "Details", format: @<a href="QuestionDetails/@item.Id">
                    <img src="../Images/ico-view-detailed.png" alt="Details" />
                </a>, style: "text-align-center")
            )
            )
    </div>
    <hr />
    <p class="result-status">
        <span>Response Time : @String.Format("{0:0.00}", percentageResult) % </span><span>Total
            Question Attend : @totalAttendQuestion </span><span class="RightAnswered">Right Answer :
                @rightAnswer
            </span><span class="WrongAnswered">Wrong Answer : @wrongAnswer </span><span class="NotAnswered">
                Not Answered : @notAnswered
            </span>
        @{
            string profileLink = "~/Account/ViewProfile/" + champs.UserId;
        }
        <a class="button thin green" href= "@Href(profileLink)">View Champion's Profile</a>
    </p>
</fieldset>
<script src="@Href("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
<script src="@Href("~/Scripts/Answer-table-color.js")" type="text/javascript"></script>